<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>国家资助管理</title>
<link rel="stylesheet" type="text/css"
	href="asserts/bootstrap-3.3.7-dist/css/bootstrap.min.css" />

<!-- js插件 -->
<script src="js/jquery-3.2.1.min.js"></script>
<script src="asserts/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css"
	href="asserts/bootstrapValidate/css/bootstrapValidator.min.css" />
<script src="asserts/bootstrapValidate/js/bootstrapValidator.min.js"></script>

</head>
<body>
	<!-- 内容展示区 -->
	<div>
		<!-- 导航 -->
		<ol class="breadcrumb">
			<li><i class="fa fa-comment"></i> 国家资助管理</li>
		</ol>
		<div class="container-fluid">
			<!-- 	内容面板 -->
			<div class="panel panel-default">
				<!-- 控制按钮 -->
				<div class="panel-heading">
					<div class="btn-group">
						<button class="btn btn-primary" onclick="addById()">
							<span class="glyphicon glyphicon-pencil"></span>添加
						</button>
						<button class="btn btn-success">
							<span class="glyphicon glyphicon-import"></span>导入excel
						</button>
						<button class="btn btn-info">
							<span class="glyphicon glyphicon-export"></span>导出excel模板
						</button>


						<label class="control-label col-md-2">学生姓名：</label>
						<div class="text-center col-md-2">
							<input type="text" name="" value="" id="selectName"
								placeholder="输入学生姓名" class="text-center form-control" />
						</div>
						<label class="control-label col-md-2">身份证号：</label>
						<div class="text-center col-md-2">
							<input type="text" name="" value="" id="selectIdCard"
								placeholder="输入身份证号码" class="text-center form-control" />
						</div>
						<div class="col-md-2">
							<button class="btn btn-success" onclick="selectByInFo()">查询</button>
						</div>

					</div>
					<!-- 控制按钮  end-->
					<div class="panel-body">
						<table class="table table-bordered table-striped" id="listtable">
							<tr>
								<th width="10%">受助项目</th>
								<th width="5%">姓名</th>
								<th width="10%">身份证</th>
								<th width="10%">受助类别</th>
								<th width="10%">金额</th>
								<th width="15%">学校</th>
								<th width="10%">乡镇</th>
								<th width="30%">操作</th>
							</tr>
							<!-- 数据绑定 -->
							<!-- <tr>
							<td><input type="checkbox" name="" class="eid" id="" /></td>
							<td>1</td>
							<td>张三</td>
							<td>扶贫项目</td>
							<td>公安县高级中学</td>
							<td>421000000</td>
							<td>低保家庭子女</td>
							<td>8000</td>
							<td>
								<button type="button" class="btn btn-primary">
									<span class="glyphicon glyphicon-edit"></span> 修改
								</button>
								<button type="button" class="btn btn-danger">
									<span class="glyphicon glyphicon-remove"></span> 删除
								</button>
								<button type="button" class="btn btn-info" onclick="detail(1)">
									<span class="glyphicon glyphicon-list"></span> 详情
								</button>
								<button type="button" class="btn btn-success"
									data-toggle="modal" data-target="#mymodal">
									<span class="glyphicon glyphicon-upload"></span> 上传扫描件
								</button>
							</td>
						</tr> -->


							<!-- 	数据绑定 end -->
						</table>
						<!-- 	分页 -->
						<nav class="text-center">
							<ul class="pagination pagination-sm" id="pageNumber">
								<!-- <li class="disabled"><a href="javascript:void(0)">&laquo;</a></li> -->

								<!-- <li><a href="">&raquo;</a></li> -->
							</ul>
						</nav>
					</div>
				</div>
				<!-- 内容面板 end -->
			</div>
		</div>
		<!-- 	内容展示区 end-->


		<!-- 弹层组件 添加标签 -->
		<div class="modal fade" id="mymodal">
			<div class="modal-dialog">
				<div class="modal-content">
					<form action="countrysub/updateByImg" class="form-horizontal">
						<!-- 隐藏域带入idcard -->
						<input type="text" name="idcard" id="idcard"
							style="display: none" value="null" class="form-control" />

						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal">
								<span>&times;</span>
							</button>
							<h4 class="modal-title" id="mylabel">
								<span class="glyphicon glyphicon-upload"></span> 上传扫描件
							</h4>
						</div>
						<div class="modal-body">
							<!-- 学校-->
							<div class="form-group">
								<label class="control-label col-md-3">申请表缩略图：</label>
								<div class="col-md-8">
									<input type="file" name="applyfile" />
								</div>
							</div>
							<!-- 学校-->
							<div class="form-group">
								<label class="control-label col-md-3">认定表缩略图：</label>
								<div class="col-md-8">
									<input type="file" name="apply2file" />
								</div>
							</div>
							<div class="form-group">
								<label class="control-label col-md-3">其他家庭经济情况作证材料缩略图：</label>
								<div class="col-md-8">
									<input type="file" name="apply3file" />
								</div>
							</div>

							<div class="form-group">
								<label class="control-label col-md-3">学生身份证正面缩略图：</label>
								<div class="col-md-8">
									<input type="file" name="idcardfile" />
								</div>
							</div>
							<div class="form-group">
								<label class="control-label col-md-3">学生身份证反面缩略图：</label>
								<div class="col-md-8">
									<input type="file" name="idcard2file" />
								</div>
							</div>
							<div class="form-group">
								<label class="control-label col-md-3">学生户口页缩略图：</label>
								<div class="col-md-8">
									<input type="file" name="stufile" />
								</div>
							</div>
							<div class="form-group">
								<label class="control-label col-md-3">学生家庭户口簿家庭成员页缩略图：</label>
								<div class="col-md-8">
									<input type="file" name="addressfile" />
								</div>
							</div>
							<div class="form-group">
								<label class="control-label col-md-3">家长或监护人户口页缩略图：</label>
								<div class="col-md-8">
									<input type="file" name="address2file" />
								</div>
							</div>
							<div class="form-group">
								<label class="control-label col-md-3">银行卡或存折缩略图：</label>
								<div class="col-md-8">
									<input type="file" name="bankfile" />
								</div>
							</div>
						</div>
						<div class="modal-footer">
							<button class="btn btn-danger" type="button">关闭</button>
							<button class="btn btn-primary" type="submit">确认上传</button>
						</div>
					</form>
				</div>
			</div>
			<!-- 隐藏域用来存放当前页码 -->
			<input type="text" id="pagenumber" style="display: none" value="1"
				class="form-control" />
		</div>
		<!-- 弹层组件 添加标签 end -->
		<script type="text/javascript">
		
		$(function() {
			// 页面加载时  查询 分类 并放入 div中 
			// 先获取当前页码:
			//var pagenumber = $("#pagenumber").attr("value");
			//alert(pagenumber);
			$.ajax({
				type : "post",
				url : "countrysub/listJson",
				//data: "currentPage="+pagenumber,
				dataType : "JSON",
				success : function(result) {
					//alert(result.list[1].project);
					var table = $("#listtable");
					//当前页面在隐藏域中刷新
					$("#pagenumber").attr("value",result.pageNum);
					
					//未录入扫描件的标红
					for (var i = 0; i < result.list.length; i++) {
						if(result.list[i].applyfile==null){
							table.append("<tr style='color:red'><td>"
									+ result.list[i].project
									+"</td><td>"
									+ result.list[i].name
									+"</td><td>"
									+ result.list[i].idcard
									+"</td><td>"
									+ result.list[i].type
									+"</td><td>"
									+ result.list[i].amount
									+"</td><td>"
									+ result.list[i].schid
									+"</td><td>"
									+ result.list[i].town
									+"</td><td><button type='button' class='btn btn-primary' onclick=\"updateById("+result.list[i].id+")\"><span class='glyphicon glyphicon-edit'></span> 修改</button>	<button type='button' class='btn btn-danger' onclick=\"deteleById("+result.list[i].id+")\"><span class='glyphicon glyphicon-remove'></span> 删除</button><button type='button' class='btn btn-info' onclick=\"detail('"+result.list[i].id+"')\"><span class='glyphicon glyphicon-list'></span> 详情</button><button type='button' class='btn btn-success'data-toggle='modal' data-target='#mymodal'><span class='glyphicon glyphicon-upload'></span> 上传扫描件</button></td></tr>");
						}else{
							table.append("<tr><td>"
									+ result.list[i].project
									+"</td><td>"
									+ result.list[i].name
									+"</td><td>"
									+ result.list[i].idcard
									+"</td><td>"
									+ result.list[i].type
									+"</td><td>"
									+ result.list[i].amount
									+"</td><td>"
									+ result.list[i].schid
									+"</td><td>"
									+ result.list[i].town
									+"</td><td><button type='button' class='btn btn-primary' onclick=\"updateById("+result.list[i].id+")\"><span class='glyphicon glyphicon-edit'></span> 修改</button>	<button type='button' class='btn btn-danger' onclick=\"deteleById("+result.list[i].id+")\"><span class='glyphicon glyphicon-remove'></span> 删除</button><button type='button' class='btn btn-info' onclick=\"detail('"+result.list[i].id+"')\"><span class='glyphicon glyphicon-list'></span> 详情</button><button type='button' class='btn btn-success'data-toggle='modal' data-target='#mymodal'><span class='glyphicon glyphicon-upload'></span> 上传扫描件</button></td></tr>");
							}
						}
						
						var ulliemp = $("#pageNumber");//获取分页的位置
						ulliemp.append("<li id='pagehead' onclick=\"selectByPage(1)\"><a href=''>&laquo;</a></li>")
						for(var j = result.navigatepageNums[0] ; j <= result.navigateLastPage; j++ ){
							ulliemp.append("<li class='' id='page"+j+"' onclick=\"selectByPage("+j+")\"><a href=''>"+j+"</a></li>");
							if(result.pageNum==j){
								$("li[id='page"+j+"']").attr("class", "active");
							}
						}
						ulliemp.append("<li id='pagetail' onclick=\"selectByPage("+result.pages+")\"><a href=''>&raquo;</a></li>");
						if(result.pageNum==1){
							$("li[id='pagehead']").attr("class", "disabled");
							//$("li[id='pagehead']").removeClass(onclick);
						}
						if(result.pageNum==result.pages){
							$("li[id='pagetail']").attr("class", "disabled");
							//$("li[id='pagetail']").removeClass(onclick);
						}
						
						
						
						
				}
			});
		})
		
		//根据页码发送请求
		function selectByPage(page) {
			//alert(page);
			//$("#pagenumber").attr("value", page);
			$.ajax({
				type : "post",
				url : "countrysub/listJson",
				data : "currentPage=" + page,
				dataType : "JSON",
				success : function(result) {
					//alert("ok");
				}
			})
		}
		
		//点击删除时候发送ajax到后台删除
		function deteleById(id) {
			$.ajax({
				type : "post",
				url : "countrysub/deleteById",
				data : "id=" + id,
				dataType : "JSON",
				success : function(result) {
					if(result==1){
						alert("删除成功");
						location.reload();
					}
				}
			})
		}
		
		//单个查询 
		function selectByInFo() {
			var idcard = $("#selectIdCard").val;
			$.ajax({
				type : "post",
				url : "countrysub/null",
				data : "id=" + id,
				dataType : "JSON",
				success : function(result) {
					if(result==1){
						alert("删除成功");
						location.reload();
					}
				}
			})
		}
		
	</script>
</body>
</html>
<script>
	 $(function () {
        $('form').bootstrapValidator({
　　　　　　　　message: 'This value is not valid',
            　feedbackIcons: {
                　　　　　　　　valid: 'glyphicon glyphicon-ok',
                　　　　　　　　invalid: 'glyphicon glyphicon-remove',
                　　　　　　　　validating: 'glyphicon glyphicon-refresh'
            　　　　　　　　   },
            fields: {
                name: {
                    message: '用户名验证失败',
                    validators: {
                        notEmpty: {
                            message: '学校名不能为空'
                        }
                    }
                },
                code: {
                    validators: {
                        notEmpty: {
                            message: '学校代码不能为空'
                        }
                    }
                },
                prop: {
                    validators: {
                        notEmpty: {
                            message: '学校性质不能为空'
                        }
                    }
                },
                level: {
                    validators: {
                        notEmpty: {
                            message: '学段不能为空'
                        }
                    }
                },
                studyyear: {
                    validators: {
                        notEmpty: {
                            message: '学年不能为空'
                        }
                    }
                }
            } ,
            submitHandler: function (validator, form, submitButton) {
              // alert("submit");
            }
        });
    });
    
   function detail(id){
   	 location.href="countorysub_detail.html?id="+id;
   }
   
   function updateById(id){
	   	 location.href="countorysub_update.html?id="+id;
	   }
	
   function addById(){
	  location.href="countorysub_add.html";
	}
   
   
   
</script>